package com.zjl.redis.第06章_SpringBoot整合redis;

import redis.clients.jedis.*;

/**
 * ClassName: jar包1_jedis
 * Package: com.zjl.redis.第06章_SpringBoot整合redis
 * Description:
 *
 * @Author 张蛟龙
 * @Create 2024/6/30 20:52
 * @Version 1.0
 */
public class B2_JedisPool {


    /**
     * JedisPool  连接池
     */
    public static JedisPool jedisPool = null;
    public static Jedis getRedisPool() {
        if(jedisPool == null){
            DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder();//创建一个设置参数的类
            JedisClientConfig redisConfig = builder.password("er485g96er8").build();//设置密码
            HostAndPort hostAndPort = new HostAndPort("82.157.71.243", 6379);

            jedisPool = new JedisPool(hostAndPort,redisConfig);

        }
        return jedisPool.getResource();
    }
    public static void main(String[] args) {
        Jedis jedis1 = getRedisPool();
        System.out.println(jedis1.ping());
        System.out.println(jedis1.get("k1"));
        jedis1.close();
    }
}
